package grex.fitnessfunctions.Regression;

import grex.GP;
import grex.Data.Prediction;
import grex.fitnessfunctions.FitnessFunction;
import grex.fitnessfunctions.IFitnessFunction;
import grex.Nodes.GeneException;

import java.io.Serializable;

/**
 *
 * @author rik
 */
public class MAPE_Fitness extends FitnessFunction implements IFitnessFunction, Serializable{

    public MAPE_Fitness() {
        super(FitnessFunction.MAPE);
    }
   public MAPE_Fitness(String name,Double instanceKey) {
        super(name,instanceKey);
    }

    @Override
    protected double calcPredictionError(Prediction prediction, double targetValue) {
        if(targetValue == 0)
            return Math.min(prediction.getPrediction(),10);
        double error = (Math.abs(prediction.getPrediction()-targetValue))/targetValue;
       return Math.min(error, 10);
    }
}
